package com.dmwork.service.work.mq.callback;

import com.dmwork.common.base.result.ExceptionUtils;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Component;

import java.lang.reflect.Method;

@Slf4j
@Data
@Component
public class ReturnCallback {

    private String callbackName;

    public static final String WORK_PUBLISH_RETURN = "workPublishReturn";
    public static final String SINGLE_FILE_REMOVE_RETURN = "singleFileRemoveReturn";
    public static final String BATCH_FILE_REMOVE_RETURN = "batchFileRemoveReturn";
    public static final String BATCH_VIDEO_REMOVE_RETURN = "batchVideoRemoveReturn";
    public static final String WORK_PUBLISH_FEED_REMOVE_RETURN = "workPublishFeedRemoveReturn";
    public static final String ADMIN_REMOVE_WORK_RETURN = "adminRemoveWorkReturn";

    public final RabbitTemplate.ReturnCallback originalReturnCallback = new RabbitTemplate.ReturnCallback() {
        @Override
        public void returnedMessage(Message message, int replyCode, String replyText, String exchange, String routingKey) {
            try {
                Method declaredMethod = ReturnCallback.class.getDeclaredMethod(callbackName, Message.class, int.class, String.class, String.class, String.class);
                declaredMethod.invoke(ReturnCallback.this, message, replyCode, replyText, exchange, routingKey);
            } catch (Exception e) {
                ExceptionUtils.getMessage(e);
            }
        }
    };

    public void workPublishReturn(Message message, int replyCode, String replyText, String exchange, String routingKey) {
        log.info("-----------------workPublish returnCallback--------------------");
        log.info("replyCode: " + replyCode);
        log.info("replyText: " + replyText);
        log.info("exchange: " + exchange);
        log.info("routingKey: " + routingKey);
    }

    public void singleFileRemoveReturn(Message message, int replyCode, String replyText, String exchange, String routingKey) {
        log.info("-----------------singleFileRemove returnCallback--------------------");
        log.info("replyCode: " + replyCode);
        log.info("replyText: " + replyText);
        log.info("exchange: " + exchange);
        log.info("routingKey: " + routingKey);
    }

    public void batchFileRemoveReturn(Message message, int replyCode, String replyText, String exchange, String routingKey) {
        log.info("-----------------batchFileRemove returnCallback--------------------");
        log.info("replyCode: " + replyCode);
        log.info("replyText: " + replyText);
        log.info("exchange: " + exchange);
        log.info("routingKey: " + routingKey);
    }

    public void batchVideoRemoveReturn(Message message, int replyCode, String replyText, String exchange, String routingKey) {
        log.info("-----------------batchVideoRemove returnCallback--------------------");
        log.info("replyCode: " + replyCode);
        log.info("replyText: " + replyText);
        log.info("exchange: " + exchange);
        log.info("routingKey: " + routingKey);
    }

    public void workPublishFeedRemoveReturn(Message message, int replyCode, String replyText, String exchange, String routingKey) {
        log.info("-----------------workPublishFeedRemove returnCallback--------------------");
        log.info("replyCode: " + replyCode);
        log.info("replyText: " + replyText);
        log.info("exchange: " + exchange);
        log.info("routingKey: " + routingKey);
    }

    public void adminRemoveWorkReturn(Message message, int replyCode, String replyText, String exchange, String routingKey) {
        log.info("-----------------adminRemoveWork returnCallback--------------------");
        log.info("replyCode: " + replyCode);
        log.info("replyText: " + replyText);
        log.info("exchange: " + exchange);
        log.info("routingKey: " + routingKey);
    }

}
